package com.hm.hall.commons.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * spring 工具, 静态方法获得 spring 注入的bean, jsp页面调用等..场景
 *
 * @author leijianjun
 */
public class SpringUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringUtils.applicationContext = applicationContext;
    }

    public static Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
    }

    public static <T> T getBean(Class<T> var1) {
        return applicationContext.getBean(var1);
    }

    public static <T> T autowired(Class<T> var1) {
        return getBean(var1);
    }

}
